package com.sugar.psych.assessment.module.business.controller.admin.basicconfig;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.sugar.psych.assessment.framework.common.pojo.PageParam;
import com.sugar.psych.assessment.framework.common.pojo.PageResult;
import com.sugar.psych.assessment.framework.common.pojo.CommonResult;
import com.sugar.psych.assessment.framework.common.util.object.BeanUtils;
import static com.sugar.psych.assessment.framework.common.pojo.CommonResult.success;

import com.sugar.psych.assessment.framework.excel.core.util.ExcelUtils;

import com.sugar.psych.assessment.framework.apilog.core.annotation.ApiAccessLog;
import static com.sugar.psych.assessment.framework.apilog.core.enums.OperateTypeEnum.*;

import com.sugar.psych.assessment.module.business.controller.admin.basicconfig.vo.*;
import com.sugar.psych.assessment.module.business.dal.dataobject.basicconfig.BasicConfigDO;
import com.sugar.psych.assessment.module.business.service.basicconfig.BasicConfigService;

@Tag(name = "管理后台 - 基本配置")
@RestController
@RequestMapping("/business/basic-config")
@Validated
public class BasicConfigController {

    @Resource
    private BasicConfigService basicConfigService;

    @PostMapping("/create")
    @Operation(summary = "创建基本配置")
    @PreAuthorize("@ss.hasPermission('business:basic-config:create')")
    public CommonResult<Boolean> createBasicConfig(@Valid @RequestBody BasicConfigSaveReqVO createReqVO) {
        basicConfigService.createBasicConfig(createReqVO);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得基本配置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('business:basic-config:query')")
    public CommonResult<BasicConfigRespVO> getBasicConfig(@RequestParam("id") Long id) {
        BasicConfigDO basicConfig = basicConfigService.getBasicConfig(id);
        return success(BeanUtils.toBean(basicConfig, BasicConfigRespVO.class));
    }

}